package com.example.test;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


import com.example.test.bean.GW;

public class MySQLiteOpenHelper_1 extends SQLiteOpenHelper {
    private static final String DB_NAME= "mySQLite.db";
    private static final String TABLE_NAME_GW = "GW";
    private static final String CREATE_TABLE_SQL = "create table " +TABLE_NAME_GW + "(id integer primary key autoincrement, carNumber text,date_1 text,w_1 text)";

    public MySQLiteOpenHelper_1(Context context){
        super(context, DB_NAME, null,1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
//添加车辆
    public long insertData(GW gw){
        SQLiteDatabase db = getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("carNumber",gw.getCarNumber());
        values.put("date_1",gw.getDate_1());
        values.put("w_1",gw.getW_1());
        return db.insert(TABLE_NAME_GW,null,values);
    }

//    删除车辆
    public int deleteFromDbByCarNumber(String CarNumber){
        SQLiteDatabase db =getWritableDatabase();
        return db.delete(TABLE_NAME_GW,"CarNumber like ?",new String[]{CarNumber});
    }
}
